/*
* @Author: 鍐伴洩
* @Date:   2018-01-29 15:49:32
* @Last Modified by:   鍐伴洩
* @Last Modified time: 2018-01-29 15:49:53
*/
//- 选择文件
$("#fileId").on("change",doUpload);
function doUpload(argument) {
	var file = this.files[0];
	//- if(!/image\/\w+/.test(file.type)) {
	//- 	alert("文件必须是图片");
	//- 	return false;
	//- }
	var formdata=new FormData($("#fileForm")[0])
	console.log(formdata);
	$.ajax({
		url:shopIp+"/Utils/uploadFiles?userToken="+token,
		type:"post",
		data:formdata,
		dataType:"json",
		async:false,
		cache:false,
		contentType:false,
		processData:false,
		success:function(data) {
			if(data.status == 200) {
				$(".hiddenTxt").val(data.data.path);
			}else{
				layer.msg(data.msg);
			}
			//$(".hiddenTxt").val(data.data.path);
		},
		error:function(data) {
			layer.msg(data.msg);
		}
	})
	$(".fileName").html($(".hiddenTxt").val());
}

//- 图片上传
$("input#orderImg").on("change", function() {
	var wrap = $(this).closest(".upimg-div");
	doUpload_img(this.files[0], function(data) {
		var imgUrl = $("input[name='order_img']").val();
		if(imgUrl) {
			$("input[name='order_img']").val(imgUrl + "," + data.data.path);
		} else {
			$("input[name='order_img']").val(data.data.path);
		}
		wrap.prepend("<span class='imgwarp'><img src='"+data.data.url+"' class='upimgs'></img><i></i></span>");
		if($("span.imgwarp img.upimgs").length > 4) {
			$("#orderImg").hide();
			$(".add-img").hide();
		}
		
	});
});
//- 点击删除图片
$(".z_photo").on("click",".imgwarp i",function() {
	$(this).closest(".imgwarp").remove();
	$("#orderImg").show();
	$(".add-img").show();
})
//- 上传图片
function doUpload_img(file, callback) {
	var formdata=new FormData($("#newOrderImg")[0])
	//console.log(formdata);
	$.ajax({
		url:shopIp+"/Utils/uploadFiles?userToken="+token,
		type:"post",
		data:formdata,
		dataType:"json",
		async:false,
		cache:false,
		contentType:false,
		processData:false,
		success:function(data) {
			//console.log(data.data.path);
			//$(".hiddenTxt").val(data.data.path);
			callback(data);
		},
		error:function(data) {
			layer.msg(data.msg);
		}
	})
}